	var index_sess_expire = 5000;		//sess缓存过期时间
	var index_cache_expire = 10000;		//静态缓存过期时间




	//获取服务列表数据
	GetServiceList(function(res){
		ParseServiceListOrInsert(res,'#service_list');
	});


	//加载底部导航栏
	Load_NavBottom('before');

	//初始化服务类别
	if(!sessionStorage.index_info_service){
		sessionStorage.index_info_service = $('#service_list').find("option:selected").val();
	}else{
		$('#service_list').find('option').each(function(i,o){	//服务选择状态维持
			if($(o).val() == sessionStorage.index_info_service){
				$(o).attr('selected',true);
			}
		});
	}

	//初始化搜索选择项
	if(!sessionStorage.search_option){
		sessionStorage.search_option = $('#search_option').find('option:selected').val();
	}else{
		$('#search_option').find('option').each(function(i,o){
			if($(o).val() == sessionStorage.search_option){
				$(o).attr('selected',true);
			}
		});
	}
	//选择项选择事件
	$("#search_option").change(function(){
		sessionStorage.search_option = $(this).find("option:selected").val();
	});



	//搜索文本框状态维持
	if(sessionStorage.search_text){
		$('#search_text').val(sessionStorage.search_text);
	}else{
		sessionStorage.search_text = '';
	}




	//服务选择事件
	$('#service_list').change(function(){
		var val = $(this).find("option:selected").val();
		sessionStorage.index_info_service = val;
		sessionStorage.removeItem('index_PageNo');	//重置当前页
		sessionStorage.search_text = '';
		$('#search_text').val('');
		Get_Infos(); 	//获取信息列表
	});

	



	$(function(){
		Set_Title();	//设置页面title
		Get_Infos(); 	//获取信息列表



		//点击搜索按钮事件
		$('#search_button').click(function(){


			var search_text = $('#search_text').val().trim();
			if(!search_text){
				sessionStorage.removeItem('search_text');
			}
			sessionStorage.search_text = search_text;
			sessionStorage.removeItem('index_PageNo');	//重置当前页
			Get_Infos();
		});
	});


	//设置sess缓存的时效
	function Set_Sess_Expire(){
		var s_time = sessionStorage.index_info_time;
		var c_time = new Date().getTime();
		if(parseInt(s_time)+index_sess_expire < c_time){				//sess缓存过期时间
			sessionStorage.index_info_time = new Date().getTime();
		}
	}

	//后台获取数据
	function Get_Remote_Data(){
		var type='Index_Get_Infos';
		Token(type,function(token){
			$.ajax({
				url:url,
				type:'post',
				async:false,
				data:{
					token:token,
					type:type,
					info_service:sessionStorage.index_info_service,	//服务类别 
				},
				success(res,a,b){
					console.log('after_get');
					//console.log(res);
					if(!/{.*}/.test(res)){
						return;
					}
					var s_time = new Date(b.getResponseHeader('Date')).getTime();	//服务器当前时间
					sessionStorage.index_s_time = s_time;	//保存服务器的时间
					var s_time = new Date(b.getResponseHeader('Date')).getTime();	//服务器当前时间
					var sess_name = 'sessionStorage.index_info'+sessionStorage.index_info_service;
					var sess_set = sess_name+"='"+JSON.stringify(JSON.parse(res).data)+"'";
					eval(sess_set);
				}
			});
		});
	}

	//缓存获取数据
	function Get_Cache_Data(){
		//统一设置sess的缓存时效
		if(!sessionStorage.index_info_time){
			sessionStorage.index_info_time = new Date().getTime();
		}else{
			Set_Sess_Expire();//设置sess缓存的时效
		}
		$.ajax({
			url:'Cache/Info_List/service_'+sessionStorage.index_info_service+'?r='+Math.random(),
			async:false,
			success(res,a,b){
				var data = JSON.parse(res);
				var c_time = data.time;	//静态缓存的时间
				var s_time = new Date(b.getResponseHeader('Date')).getTime();	//服务器当前时间
				sessionStorage.index_s_time = s_time;	//保存服务器的时间
				if(c_time < (s_time-index_cache_expire)){	//远程静态缓存过期时间
					Get_Remote_Data();
				}else{
					console.log('cache_get');
					//sessionStorage.index_info = JSON.stringify(data.data);
					//sessionStorage.index_info_time = new Date().getTime();
					var sess_name = 'sessionStorage.index_info'+sessionStorage.index_info_service;
					var sess_set = sess_name+"='"+JSON.stringify(data.data)+"'";
					eval(sess_set);
					//Set_Sess_Expire();//设置sess缓存的时效

				}
			},
			error(){ //缓存不存在时向后台加载数据
				Get_Remote_Data();
			}
		});
	}




	//获取信息列表
	function Get_Infos(){
		//判断sess缓存是否存在，并从远程缓存或后台获取数据
		var sess_name = 'sessionStorage.index_info'+sessionStorage.index_info_service;
		if(!eval(sess_name) || !sessionStorage.index_info_time){
			Get_Cache_Data();	//从缓存或后台加载数据
		}else{
			var s_time = sessionStorage.index_info_time;
			var c_time = new Date().getTime();
			if(parseInt(s_time)+index_sess_expire < c_time){				//sess缓存过期时间
				Get_Cache_Data();	//从缓存或后台加载数据
			}else{
				console.log('sess_get');
			}
		}
		if(!eval(sess_name)){
			alert('没有更多数据了!');
			$('#fpage').html('');
			$("#Index_InfoList").html('');return;
		}
		var sess_infos = JSON.parse(eval(sess_name));	//解析缓存数据

		var infos = new Array();
		//全部服务
		if(sessionStorage.index_info_service == 'all'){
			if(sessionStorage.search_text){
				for(var i=0;i<sess_infos.length;i++){
					if(sess_infos[i][1].match(sessionStorage.search_text)){
						infos.push(sess_infos[i]);
					}
				}
			}else{
				infos = sess_infos;
			}

		}else{	//指定服务
			if(sessionStorage.search_text){
				for(var i=0;i<sess_infos.length;i++){
					if(sess_infos[i][3] == sessionStorage.index_info_service && sess_infos[i][1].match(sessionStorage.search_text)){
						infos.push(sess_infos[i]);
					}
				}
			}else{
				for(var i=0;i<sess_infos.length;i++){
					if(sess_infos[i][3] == sessionStorage.index_info_service){
						infos.push(sess_infos[i]);
					}
				}
			}
		}








		var infos_str = '';
		var service_type = JSON.parse(sessionStorage.service_type);

		var psize = 10;	//每页条数
		//初始化当前页
		if(!sessionStorage.index_PageNo){
			sessionStorage.index_PageNo = 1;
		}
		//初始化总页数
		sessionStorage.index_PageCount = Math.ceil(infos.length / psize);
		var loop_start = (parseInt(sessionStorage.index_PageNo) -1)*psize;
		var loop_end = loop_start + psize;
/*
		[0]info_id,
		[1]info_title,
		[2]info_issue_time,
		[3]info_service
		[4]info_auto_issue
*/
		for(var i=loop_start;i<loop_end;i++){
			if(infos[i] != undefined){
					var service_name = Get_ServiceType_Name(service_type,infos[i][3]);
					if(infos[i][4] == 1){
						var t = new Date(parseInt(sessionStorage.index_s_time));
					}else{
						var t = new Date(parseInt(infos[i][2])*1000);
					}
					var t2 = t.getFullYear()+'-'+(t.getMonth()>=9?t.getMonth()+1:'0'+(t.getMonth()+1))+'-'+(t.getDate()>=10?t.getDate():'0'+t.getDate());
					infos_str += "<div class='Index_InfoItem' onclick=Info_Cat("+infos[i][0]+",'index') style='display:flex;border-bottom:2px solid #aaa;border-top:1px solid #aaa;margin-top:5px'>";

					infos_str += "<div style='width:20px;border-right:1px solid #aaa;text-align:center;padding:3px 2px;font-size:12px'>"+service_name+"</div>";

					infos_str += "<div style='flex:5;display:flex;flex-direction:column;word-break:break-all;background:#ddd;padding:5px'>";

					infos_str += "<div>"+infos[i][1]+"</div><div style='font-size:12px'></div>";

					infos_str += "<div style='font-size:12px;display:flex'><div style='flex:2'>"+city_xian+"</div><div style='flex:3;text-align:right'>发布时间："+t2+"</div></div></div></div>";
			}
		}
		$("#Index_InfoList").html(infos_str);

		//设置分页
		Fpage2(function(pnow){
			sessionStorage.index_PageNo = pnow;
			Get_Infos();
		});	
	}











	/*
	    ### 设置分页码
	        参一：总页数
	        参二：当前页数
	        参三：是否携带其它url参数
	        需要一个id为 fpage 的容器元素 如 <div style="text-align:center;margin:20px" id="fpage"> </div>
	*/
	function Fpage2(fun) {
		PageNo = parseInt(sessionStorage.index_PageNo);
		PageCount = parseInt(sessionStorage.index_PageCount);
		var fpage_size = 2;
	    var start = PageNo - fpage_size;
	    if (start < 1) {
	        start = 1;
	    }
	    var end = PageNo + fpage_size;
	    if (end > PageCount) {
	        end = PageCount;
	    }
	    var fpage_str = '';
	    if(PageNo != 1 && PageCount > 3){
	    	fpage_str += "<a style='margin:5px;border:1px solid;padding:3px 5px;color:#aaa' PageNo='1' >首页</a>";
	    }
	    for (var i = start; i <= end; i++) {
	        if (PageNo == i) {
	            fpage_str += "<a style='margin:5px;border:1px solid blue;padding:3px 5px;color:#fff;background:blue' PageNo=" + i + ">" + i + "</a>";
	        } else {
	            fpage_str += "<a style='margin:5px;border:1px solid;padding:3px 5px;color:#aaa' PageNo=" + i + ">" + i + "</a>";
	        }
	    }
	    $("#fpage").html(fpage_str);
	    $("#fpage a").click(function () {
	    	if(PageNo == $(this).attr('PageNo')){
	    		return;
	    	}
	        PageNo = $(this).attr('PageNo');
	        fun(PageNo);
	    });
	}



